<template>
  <div>
    <el-button
      v-if="false"
      type="primary"
      size="small"
      @click="onClickRefresh()"
    >
      刷新
    </el-button>
    <el-table :data="data" style="width: 100%" v-loading="loading">
      <el-table-column prop="id" label="序号" width="60px" align="center">
      </el-table-column>
      <el-table-column prop="value" label="服务器" min-width="250px">
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from "vue";
import request from "../../../request";
const data = ref<any[]>([]);
const loading = ref<Boolean>(false);
const props = defineProps({
  serverLocation: String,
});
onMounted(() => {
  getData();
});
const onClickRefresh = () => {
  getData();
};
const getData = async () => {
  loading.value = true;
  let param = {
    serverLocation: props.serverLocation,
  };
  let result = await request
    .get("/gameServer/server/servers", param)
    .catch((error) => {
      console.log(error);
    });
  const json = result.data;

  console.log(result.data);

  const resultData: any[] = [];
  if (Array.isArray(json)) {
    json.forEach((item, index) => {
      const resultDataItem = {
        id: index,
        value: item,
      };

      resultData.push(resultDataItem);
    });
  }

  data.value = resultData;
  loading.value = false;
};
</script>
